//
//  SNLineView.m
//  SinaNews
//
//  Created by bond on 13-9-26.
//  Copyright (c) 2013年 sina. All rights reserved.
//

#import "SNLineView.h"

@implementation SNLineView
@synthesize startPoint = _startPoint;
@synthesize endPoint   = _endPoint;
@synthesize lineColor  = _lineColor;

- (void)dealloc
{
    if (_lineColor) {
        [_lineColor release];
    }
    _lineColor = nil;
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.startPoint = CGPointZero;
        self.endPoint = CGPointZero;
        self.lineColor = nil;
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

//直线
-(void)drawLineFrom:(CGPoint)startPoint
                 to:(CGPoint)endPoint
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextMoveToPoint(context, startPoint.x, startPoint.y);
    CGContextAddLineToPoint(context, endPoint.x,endPoint.y);
    
    CGContextStrokePath(context);
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    if (self.lineColor != nil) {
        [self.lineColor setStroke];
        [self drawLineFrom:self.startPoint to:self.endPoint];
    }
}
@end
